package demo.insight;


import java.io.FileInputStream;
import java.time.Instant;

/**
 * @author : feixiang.li
 * @since : 2025-09-17 10:45
 */
public class ReadMain {
    public static void main(String[] args) {
        // 一共11mb
        String path = "/Users/luckincoffee/Desktop/下载/kafka-trunk.zip";
        long l = Instant.now().toEpochMilli();
        try (MyBufferedFileInputStream myBufferedFileInputStream =
                     new MyBufferedFileInputStream(new FileInputStream(path), 1024 * 1024)) {
            byte[] bytes = new byte[1024 * 1024];
            int len;
            while ((len = myBufferedFileInputStream.read(bytes)) != -1) {
            }
            System.out.println("耗时：" + (Instant.now().toEpochMilli() - l) + "毫秒");
        } catch (Exception e) {
            e.printStackTrace();
        }

        // 使用原始方式读取
        long l1 = Instant.now().toEpochMilli();
        try (FileInputStream fileInputStream = new FileInputStream(path)) {
            int len;
            while ((len = fileInputStream.read()) != -1) {
            }
            System.out.println("耗时：" + (Instant.now().toEpochMilli() - l1) + "毫秒");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
